<template>
	<view class="message-wrap">
		<!--
		<u-message-item v-for="(item, index) in sessions" :key="index" :data="item" :type="0" @click="gotoRouter('/pages-im/chatRoom/chatRoom?accid=' + item.to+'&role=1')"></u-message-item>
		-->
		<u-message-item v-for="(item, index) in conversationList" :key="index" :data="item" :type="0" @click="toMessageDetails(item)"></u-message-item>
		<u-empty-state v-if="conversationList.length == 0" value="暂无相关问诊消息"></u-empty-state>
		
		
	</view>
</template>

<script>
import uMessageItem from '@/components/u-message-item/u-message-item.vue';
import uEmptyState from '@/components/u-empty-state/u-empty-state.vue';
import { mapState, mapMutations } from 'vuex';
import { imInfo, currentImInfo } from '@/utils/token.js';
const app = getApp();
export default { 
	components: {
		uMessageItem,
		uEmptyState
	},
	computed: {
		...mapState(['hasLogin']),
		// ...mapState('im', { sessions: 'sessions', personList: 'personList', unreadTotalNum: 'unreadTotalNum' })
	},
	data() {
		return {
			conversationList: []
		};
	},
	onLoad(option) {
		// this.fetchConversationList();
	},
	created(option) {
		this.fetchConversationList();
	},
	mounted() {
		// this.$store.dispatch('txyIm/SessionUnreadInfo_update', this.conversationList)
	},
	onShow() {
		// this.$store.dispatch('im/SessionUnreadInfo_update', this.sessions)
		// this.$store.dispatch('txyIm/SessionUnreadInfo_update', this.conversationList)
	},
	methods: {
		toMessageDetails(c) {
			// gotoRouter('/pages-txy-im/chatRoom/chatRoom?accid=' + item.userProfile.userID+'&role=0')
			const userId = c.userProfile.userID
			const doctorId = currentImInfo.get().id
			const params = {
				userId,
				doctorId
			}
			this.$api.fetchQuestionOrderId({ data: params }).then(res => {
				if (res.code == 200) {
					if (res.result) {
						const questionOrderId = res.result
						uni.navigateTo({
							url: '/pages-txy-im/chatRoom/chatRoom?accid=' + c.userProfile.userID+'&role=1&questionOrderId=' + questionOrderId
						})
					}
				}
				if (res.code == 500) {
					uni.navigateTo({
						url: '/pages-txy-im/chatRoom/chatRoom?accid=' + c.userProfile.userID+'&role=1'
					})
				}
			})
		}
	}
};
</script>

<style lang="less">
@import './doctorMessage.less';
</style>
